package com.REPDPMSystem.Service.Handler;

import com.REPDPMSystem.Service.FolderService;
import com.REPDPMSystem.Entity.Folder;
import com.REPDPMSystem.Mapper.FolderMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class FolderHandler extends ServiceImpl<FolderMapper, Folder> implements FolderService {

    @Override
    public List<Folder> getRootFolderByProjectId(String projectId){
        QueryWrapper<Folder> wrapper = new QueryWrapper<>();
        wrapper.eq("project_id",projectId)
               .eq("parent_id","null");
        return baseMapper.selectList(wrapper);
    }
    @Override
    public List<Folder> getFolderByParentFolderId(String parentFolderId){
        QueryWrapper<Folder> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",parentFolderId);
        return baseMapper.selectList(wrapper);
    }
    @Override
    public List<Folder> getEmployeeInfoByName(String name,String parent_id){
        QueryWrapper<Folder> wrapper = new QueryWrapper<>();
        wrapper.like("file_name",name)
                .eq("parent_id",parent_id);
        return baseMapper.selectList(wrapper);

    }
    @Override
    public int createNewFolder(Folder folder){
        folder.setFolder_id(UUID.randomUUID().toString());
        return baseMapper.insert(folder);
    }
//有没有子文件夹，有的话能不能递归删除？
    @Override
    public boolean deleteFolderByFolderId(String folderId){
        QueryWrapper<Folder> wrapper = new QueryWrapper<>();
        wrapper.eq("folder_id", folderId);

        return baseMapper.delete(wrapper)>0;
    }

}
